<template>
  <h4>当前的x值是{{ x }}</h4>
  <button @click="x++">点我x加一</button>
  <hr>
  <h3>{{ person }}</h3>
  <h2>姓名：{{ name }}</h2>
  <h2>年龄：{{ age }}</h2>
  <h2>薪资：{{ job.j1.salary }}</h2>
  <button @click="name += '~'">修改姓名</button>
  <button @click="age ++ ">增长年龄</button>
  <button @click="job.j1.salary ++ ">张薪</button>
</template>

<script>
import {shallowReactive, shallowRef, toRefs} from 'vue'

export default {

  setup() {
    // 数据
    let person = shallowReactive({ // 只考虑第一层数据的响应式
      name: 'achao',
      age: 18,
      job: {
        j1: {
          salary: 100
        }
      }
    })

    let x = shallowRef(0)

    // 返回一个对象
    return {
      person,
      ...toRefs(person),
      x
    }
  }
}
</script>

<style scoped>

</style>
